import request from '@/utils/request.js'

// 获取手机验证码

const  getMobileCode = (mobile) =>{
    return request.get(`/v1_0/sms/codes/${mobile}`)
}

// 手机号验证码登录

const userLogin = (loginInfo) =>{
    return request.post('/v1_0/authorizations',loginInfo)
}

// 获取用户信息

const getUserInfo = () =>{
    return request.get('/v1_0/user')
}

// 获取用户的频道

const getUserChannels = () =>{
    return request.get('/v1_0/user/channels')
}

// 关注用户

const addFollows = (articleId) =>{
    return request({
        url: '/v1_0/user/followings',
        method: 'POST',
        data: {
          target: articleId
        }
    })
}

// 取消关注用户

const deleteFollows = (articleId) => {
    return request({
        url: `/v1_0/user/followings/${articleId}`,
        method: 'DELETE'
    })
}

// 获取用户个人资料

const getUserProfile = () => {
    return request({
        url: '/v1_0/user/profile',
        method: 'GET',
    })
}

// 修改用户头像

const changeUserPhoto = (data) => {
    return request({
        url: '/v1_0/user/photo',
        method: 'PATCH',
        data 
    })
}

//修改用户信息

const editUserInfo = (userInfo) => {
    return request({
        url: '/v1_0/user/profile',
        method: 'PATCH',
        data : {
            ...userInfo
        }
    })
}

// 获取用户阅读历史

const getUserReadHistory = (queryInfo) => {
    return request({
        url: '/v1_0/user/histories',
        method: 'GET',
        params: {
            ...queryInfo
        }
    })
}

// 获取用户收藏记录

const getUserCollection = (queryInfo) => {
    return request({
        url: '/v1_0/article/collections',
        method: 'GET',
        params: {
            ...queryInfo
        }
    })
}
// 获取用户消息通知

const getUserNotice = (queryInfo) => {
    return request({
        url: 'v1_0/user/notify',
        method: 'GET',
        params: {
            ...queryInfo
        }
    })
}

// 获取用户作品
const getUserCreatedArticle = (queryInfo) => {
    return request({
        url: 'v1_0/user/articles',
        method: 'GET',
        params: {
            ...queryInfo
        }
    })
}

// 获取用户统计数据

const getUserFigure = () => {
    return request({
        url: '/v1_0/user/figure',
        method: 'GET',
    })
}

// 获取公告

const getAnnouncements = (queryInfo) => {
    return request({
        url: '/v1_0/announcements',
        method: 'GET',
        params: {
            ...queryInfo
        }
    })
}

// 获取我的关注

const getUserFollows = (queryInfo) => {
    return request({
        url: '/v1_0/user/followings',
        method: 'GET',
        params: {
            ...queryInfo
        }
    })
}

// 获取我的粉丝

const getUserFans = (followerQuery) => {
    return request({
        url: '/v1_0/user/followers',
        method: 'GET',
        params: {
            ...followerQuery
        }
    })
}
export {
    getMobileCode,
    userLogin,
    getUserInfo,
    getUserChannels,
    addFollows,
    deleteFollows,
    getUserProfile,
    changeUserPhoto,
    editUserInfo,
    getUserReadHistory,
    getUserCollection,
    getUserNotice,
    getUserCreatedArticle,
    getUserFigure,
    getAnnouncements,
    getUserFollows,
    getUserFans
    
}